// 翻滚加载(热搜部分)
// 思路;向下翻滚，页数加一，请求发送一次，渲染一次
var currentPage = 1;
// 判断数据是否为0
var url;

function getrestMsg() {
  console.log("加载");
  $(window).scroll(function () {
    if (
      Math.round($(window).scrollTop() + $(window).height()) ==
      $(document).height()
    ) {
      currentPage++;
      $.ajax({
        url: `/weibo/user/getLoadedOthersCommentOfMe?pageNo=${currentPage}&pageSize=10`,
        type: "get",
        data: {},
        success: function (result) {
          console.log(result);
          let allnews = document.querySelector("#news");
          if (result.length == 10) {
            console.log(result.length);

            for (let i = 0; i < result.length; i++) {
              //   判断是赞评论还是赞文章
              let comment = result[i];
              let state = result[i].state;
              let myInfo = result[i].myInfo;
              let othersInfo = result[i].othersInfo;

              if (!result[i].blogUrl) {
                url = result[i].myInfo.avatarUrl;
              } else {
                url = result[i].blogUrl;
              }
              if (state == 0) {
                allnews.innerHTML += `
                <div class="news add" >
                <div class="news-top">
                  <a  href="/user/toOnesInfo?id=${comment.userId}" class="head-link">
                    <div class="head">
                      <img src="${othersInfo.avatarUrl}"  alt="" />
                    </div>
                  </a>
                  <div class="top-details">
                    <a href="" class="name" >
                      <p >${othersInfo.username}</p>
                    </a>
                    <p class="time" >${comment.likeTime} ${comment.othersInfo.address}</p>
                  </div>
                </div>
                <div class="message-content" href="/weibo/blog/skipInEnvelope?id=${comment.blogId}" ><p 
                >${comment.otherCommentText}</p></div>
                <a class="message-container" >
                  <div class="message-content-img">
                    <img src="${url}"  alt="" />
                    
                  </div>
                  <div class="message-content-text">
                    <p><span>@</span><span >${comment.myInfo.username}</span></p>
                    <p   class="message-content-blog">${comment.blogText}</p>
      
                  </div>
                </a>
                <div class="foot" >
                <div class="reply" cid="${comment.commentId}">
                <i class="iconfont">&#xe695;</i>
                <span class="rep">回复</span>
              </div>
              <div
                class="likeComment"
                cid="${comment.commentId}"
                onclick="likeComment(this)"
              >
                <i class="iconfont">&#xe62b;</i>
              </div>
              </div>
                `;
              } else if (state == 1) {
                allnews.innerHTML += `
                <div class="news add" >
                <div class="news-top">
                  <a  href="/user/toOnesInfo?id=${comment.userId}" class="head-link">
                    <div class="head">
                      <img src="${othersInfo.avatarUrl}"  alt="" />
                    </div>
                  </a>
                  <div class="top-details">
                    <a href="" class="name" >
                      <p >${othersInfo.username}</p>
                    </a>
                    <p class="time" >${comment.likeTime} ${comment.othersInfo.address}</p>
                  </div>
                </div>
                <div class="message-content" ><p>
                回复
                <a class="color" >@${comment.myInfo.username}</a
                >:<span >${comment.otherCommentText}</span>
              </p></div>
               
                <div class="message-container-box" href="/weibo/blog/skipInEnvelope?id=${comment.blogId}">
                  <div class="message-container-item1" ><a class="color">@${comment.myInfo.username}</a><span >:${comment.commentText}</span></div>
                  <div class="message-container">
                    <div class="message-content-img">
                      <img src="${url}" alt="" />
                     
                    </div>
                    <div class="message-content-text">
                      <p>
                        <span>@</span><span th:text="">${comment.myInfo.username}</span>
                      </p>
                      <p  class="message-content-blog">${comment.blogText}</p>
                    </div>
                  </div>
                </div>

                <div class="foot" >
                <div
                  class="likeComment"
                  cid="${comment.commentId}"
                  onclick="likeComment(this)"
                >
                  <i class="iconfont">&#xe62b;</i>
                </div>
              </div>




              </div>
                `;
              }
            }
          } else if (result.length > 0 && result.length < 10) {
            for (let i = 0; i < result.length; i++) {
              let comment = result[i];
              let state = result[i].state;
              let myInfo = result[i].myInfo;
              let othersInfo = result[i].othersInfo;

              if (!result[i].blogUrl) {
                url = result[i].myInfo.avatarUrl;
              } else {
                url = result[i].blogUrl;
              }
              if (state == 0) {
                allnews.innerHTML += `
                  <div class="news add" >
                  <div class="news-top">
                    <a  href="/user/toOnesInfo?id=${comment.userId}" class="head-link">
                      <div class="head">
                        <img src="${othersInfo.avatarUrl}"  alt="" />
                      </div>
                    </a>
                    <div class="top-details">
                      <a href="" class="name" >
                        <p >${othersInfo.username}</p>
                      </a>
                      <p class="time" >${comment.likeTime} ${comment.othersInfo.address}</p>
                    </div>
                  </div>
                  <div class="message-content" ><p 
                  >${comment.otherCommentText}</p></div>
                  <div class="message-container">
                    <div class="message-content-img">
                      <img src="${url}"  alt="" />
                      
                    </div>
                    <div class="message-content-text">
                      <p><span>@</span><span >${comment.myInfo.username}</span></p>
                      <p   class="message-content-blog">${comment.blogText}</p>
        
                    </div>
                  </div>
                  <div class="foot" >
                  <div class="reply" cid="${comment.commentId}">
                  <i class="iconfont">&#xe695;</i>
                  <span class="rep">回复</span>
                </div>
                <div
                  class="likeComment"
                  cid="${comment.commentId}"
                  onclick="likeComment(this)"
                >
                  <i class="iconfont">&#xe62b;</i>
                </div>
                </div>
                  `;
              } else if (state == 1) {
                allnews.innerHTML += `
                  <div class="news add" >
                  <div class="news-top">
                    <a  href="/user/toOnesInfo?id=${comment.userId}" class="head-link">
                      <div class="head">
                        <img src="${othersInfo.avatarUrl}"  alt="" />
                      </div>
                    </a>
                    <div class="top-details">
                      <a href="" class="name" >
                        <p >${othersInfo.username}</p>
                      </a>
                      <p class="time" >${comment.likeTime} ${comment.othersInfo.address}</p>
                    </div>
                  </div>
                  <div class="message-content" ><p>
                  回复
                  <a class="color" >@${comment.myInfo.username}</a
                  >:<span >${comment.otherCommentText}</span>
                </p></div>
                 
                  <div class="message-container-box">
                    <div class="message-container-item1" ><a class="color">@${comment.myInfo.username}</a><span >:${comment.commentText}</span></div>
                    <div class="message-container">
                      <div class="message-content-img">
                        <img src="${url}" alt="" />
                       
                      </div>
                      <div class="message-content-text">
                        <p>
                          <span>@</span><span th:text="">${comment.myInfo.username}</span>
                        </p>
                        <p  class="message-content-blog">${comment.blogText}</p>
                      </div>
                    </div>
                  </div>
  
                  <div class="foot" >
                  <div
                    class="likeComment"
                    cid="${comment.commentId}"
                    onclick="likeComment(this)"
                  >
                    <i class="iconfont">&#xe62b;</i>
                  </div>
                </div>  
                </div>
                  `;
              }
            }
            allnews.innerHTML += `<p class="none">暂时没有其他内容了</p>`;
            YesOrNo();
            func();
            replyWindow();
          }
        },
        error: function () {
          console.log("加载失败");
        },
      });
    }
  });
}
if (!document.querySelector("#message-news")) {
  getrestMsg();
}
